package test.de.westranger.forex.trading.genetic.allel.crossover;

import java.util.Random;

public class CustomRandom extends Random {

	private static final long serialVersionUID = 1L;
	private final double[] values;
	private int pos;

	public CustomRandom(final double[] values) {
		this.pos = 0;
		this.values = values;
	}

	@Override
	public double nextDouble() {
		if (this.pos >= this.values.length) {
			this.pos = 0;
		}
		//System.out.println(this.values[pos]);
		return this.values[pos++];
	}

	@Override
	public int nextInt(final int arg0) {
		if (this.pos >= this.values.length) {
			this.pos = 0;
		}
		//System.out.println((int)Math.round(this.values[pos]));
		return (int) Math.round(this.values[pos++]);
	}
	
	@Override
	public boolean nextBoolean(){
		if (this.pos >= this.values.length) {
			this.pos = 0;
		}
		//System.out.println((int)Math.round(this.values[pos]) + "b");
		return this.values[pos++] == 1.0 ? true: false;		
	}
	
}
